<template>
 <!-- 购物车内容 -->
  <view class="cart-container" v-if="cart.length !== 0">
    <!-- 收货地址部分 -->
    <my-address></my-address>
    <!-- 标题部分 -->
    <view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <!-- 标题文本 -->
      <text class="cart-title-text">购物车</text>
    </view>
    <!-- 商品列表部分 -->
    <uni-swipe-action>
      <block class="goods-item" v-for="(item, i) in cart" :key="i">
      <uni-swipe-action-item :options="options" @click="onClick(item.goods_id)">
        <my-goods :goods="item" :show-radio="true" :show-num="true" @radios-change="changeRadios"
          @num-change="changeNum"></my-goods>
      </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
        
        <my-settle></my-settle>
  </view>
  <!-- 购物车为空 -->
  <view class="kongkong" v-else >
    <image src="/static/cart_empty@2x.png"  class="bg"></image>
    <text>空空如也~</text>
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState('cart', ['cart'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }]
      };
    },
    methods: {
      ...mapMutations('cart', ['updataGoodsState', 'updataGoodsCount', 'subCart', 'updataAllState']),
      changeRadios(e) {
        console.log(e)
        this.updataGoodsState(e)
      },
      changeNum(e) {
        this.updataGoodsCount(e)
      },
      onClick (id) {
        this.subCart(id)
      }
    }
  }
</script>

<style lang="scss">
  .cart-container {
    margin-bottom: 50px;
  }
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    font-size: 14px;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    .cart-title-text {
      margin-left: 10px;
    }
  }
.kongkong {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;
  .bg {
    width: 80px;
    height: 80px;
  }
  text {
    margin-top: 10px;
    font-size: 14px;
  }
}
</style>
